package edu.ues21.tcs.ecommerce2011.mvc.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import edu.ues21.tcs.ecommerce2011.mvc.dao.ArticuloDAO;
import edu.ues21.tcs.ecommerce2011.mvc.dao.ArticuloPrecioDAO;
import edu.ues21.tcs.ecommerce2011.mvc.model.ArticuloPrecio;

/**
 * 
 * @author fmantaras.
 */
public class ListarArticuloPreciosAdminController extends HttpServlet {

	ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext(
			"/BeanLocations.xml");

	ArticuloPrecioDAO apDao = (ArticuloPrecioDAO) appContext.getBean("articuloprecioDAO");
	ArticuloDAO aDao = (ArticuloDAO) appContext.getBean("articuloDAO");

	private static final long serialVersionUID = 1L;

	protected void processRequest(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

	}

	@Override
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

	}

	@Override
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {


		Integer listaPrecio = Integer.parseInt(request.getParameter("id").trim());
		List<ArticuloPrecio> lista = apDao.getAllLista(listaPrecio);
		
		request.setAttribute("cantidadArticulos", aDao.total());
		request.setAttribute("lista", lista);
		request.setAttribute("listaPrecio", listaPrecio);
		request.getRequestDispatcher("view/CRUDArticuloPrecio.jsp").forward(
				request, response);
	}

	@Override
	public String getServletInfo() {
		return "Short description";
	}// </editor-fold>

}
